package com.zhuiyun.project.api.system.register.controller;

import com.zhuiyun.project.api.system.register.service.RegisterService;
import com.zhuiyun.project.api.system.user.entity.SysUser;
import com.zhuiyun.project.common.controller.BaseController;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName registerController
 * @Description TODO
 * @Author Administrator
 * @Date 2023/11/3 8:46
 **/
@Slf4j
@RestController
@RequestMapping("/register")
public class RegisterController extends BaseController {
    @Autowired
    private RegisterService registerService;


    /**
    * @Author Administrator
    * @Description 注册账号
    * @Date 2023/11/3 10:25
    * @Return com.zhuiyun.project.common.response.CommonResult
    */
    @PostMapping("/register-user")
    public CommonResult registerUser(@RequestBody Map map) throws Exception{
        log.info("注册");
        SysUser sysUser = new SysUser();
        sysUser.setEmail(map.get("email").toString());
        sysUser.setPassword(SecurityUtils.encryptPassword(map.get("password").toString()));
        sysUser.setLoginName(map.get("loginName").toString());
        sysUser.setPhone(map.get("phone").toString());
        sysUser.setUserName(map.get("loginName").toString());
        sysUser.setCreateBy(map.get("loginName").toString());
        String emailCode = map.get("emailCode").toString();

        return registerService.userRegister(sysUser, emailCode);
    }
}
